package com.sunnada.weixin.util.weixinPay;





import java.io.*;
import java.util.Properties;

import org.apache.log4j.Logger;


/**
 * 
 * @Title: 读取配置文件
 * @Description:
 * @Copyright: Copyright (c) 2014 sunnada All Rights Reserved 
 * @author     yewg     2014-9-22 
 * @version 1.00.000 
 * @Company: 福建三元达软件有限公司
 * @Modify-history
 */
public class LoadConfig {
    private static Logger logger = Logger.getLogger(LoadConfig.class);

   

    /**
     * 根据文件路径读入配置文件
     * 
     * @param fileName
     * @return
     */
    public static Properties getConfigFromPath(String path) {
        Properties prop = new Properties();
        try {
            InputStream fin = LoadConfig.class.getResourceAsStream(path);
            BufferedInputStream bi = new BufferedInputStream(fin);
            prop.load(bi);
            bi.close();
            fin.close();
        } catch (Exception e) {
            logger.error("读工程配置文件：" + path + "失败！", e);
        }
        return prop;
    }

    /**
     * 根据文件名读入配置文件
     * 
     * @param fileName
     * @return
     */
    public static Properties getConfigFromFile(String fileName) {
        Properties prop = new Properties();
        try {
            InputStream fin = LoadConfig.class
                    .getResourceAsStream("/com/ffcs/upcfj/common/resource/"
                            + fileName);
            BufferedInputStream bi = new BufferedInputStream(fin);
            prop.load(bi);
            bi.close();
            fin.close();
        } catch (Exception e) {
            logger.error("读工程配置文件：" + fileName + "失败！", e);
        }
        return prop;
    }

    /**
     * 
     * @param fileName
     * @return
     */
    public static Properties getConfigFile(String fileName) {
        Properties p = new Properties();
        try {
            File f = new File(fileName);
            FileInputStream in = new FileInputStream(f);
            p.load(in);
            in.close();
        } catch (Exception e) {
            logger.error("读工程配置文件：" + fileName + "失败！", e);
        }
        return p;
    }
    
    /**
     * 
     * @param path
     * @return
     */
    public static InputStream getConfigFromClassPath(String path) {
        InputStream input = null;
        try {
            input = LoadConfig.class.getResourceAsStream(path);
        } catch (Exception e) {
            logger.error("读工程配置文件：" + path + "失败！", e);
        }
        return input;
    }
    
}
